﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ServicesLibrary.Models;

namespace ServicesLibrary.DataAccessLayer
{
    public class DataAccesHelper
    {
        ServicesDataContext db = new ServicesDataContext();

        public bool checkLogin(string USERNAME, string PASSWORD)
        {
            var existaccount = from m in db.LOGINs
                               where (m.USERNAME == USERNAME) && (m.PASSWORD == PASSWORD)
                               select m;
            if (existaccount.Any())
                return true;
            return false;

        }
        public string getCurrentDisplayName(string USERNAME)
        {
            var user = (from m in db.PROC_GetUserInfo(USERNAME) select m).FirstOrDefault();

            return user.DISPLAY_NAME;
        }
        public AuthenticationModel getAuthenticationInfo(string USERNAME, string PASSWORD)
        {
            var user = (from m in db.PROC_GetUserInfo(USERNAME) select m).FirstOrDefault();

            if (user != null)
            {
                AuthenticationModel model = new AuthenticationModel();
                model.USERNAME = user.USERNAME;
                model.PASSWORD = user.PASSWORD;
                model.ROLE_ID = user.ROLE_ID.ToString();
                model.IS_ACTIVE = user.IS_ACTIVE;
                return model;
            }
            else
                return null;
        }

        public PROC_GetUserInfoResult getUserInfo(string USERNAME)
        {
            return (from m in db.PROC_GetUserInfo(USERNAME) select m).FirstOrDefault();
        }

    }
}